package com.forekonw.demotest1026;

import java.util.Scanner;
//欢迎1
public class banktext {
    public static void q1(){
        System.out.println("----------------------------------");
        System.out.println("******        欢迎登录       ******");
        System.out.println("******      中国人民银行     ******");
        System.out.println("*****         版本1.0         *****");
        System.out.println("----------------------------------");
    }
//登录2
    public static boolean q2(String a,int b){
        Scanner input = new Scanner(System.in);
        System.out.println("请输入账号：");
        String zhanghao = input.next();
        System.out.println("请输入密码： ");
        int mima = input.nextInt();
        if (zhanghao.equals(a)&&mima==b){
            return true;
        }else {
            return false;
        }
    }
//查询3
    public static void q3(double yue){
        double gold =yue;
        System.out.println("您当前的余额为"+gold);
    }
//存款4
    public static double q4(double money,double yue){
        if (money>10000){
            //10000
            System.out.println("单次取款金额超过一万元");
            return yue;
        }else if (money<0){
            //-
            System.out.println("存款金额错误");
            return yue;
        }else if (money%100!=0){
            //100
            System.out.println("请输入一百的整数倍存款");
            return yue;
        }else {
            System.out.println("存款成功，当前余额为："+(money+yue));
            return money+yue;
        }
    }
//取款 5
    public static double q5(double money,double yue){
        if (money>yue){
            System.out.println("余额不足");
            return yue;
        }else if (money>3000){
            System.out.println("单次取款金额超过3000元");
            return yue;
        }else if (money<0){
            System.out.println("取款金额错误");
            return yue;
        }else if (money%100!=0){
            System.out.println("请取出一百的整数倍存款");
            return yue;
        }else {
            System.out.println("取款成功，当前余额为："+ (yue-money));
            return yue-money;
        }
    }
 //修改密码6
    public static int q6(int mima,int jiumima){
        if (mima==jiumima){
            Scanner input = new Scanner(System.in);
            System.out.println("请输入新密码：");
            int a =input.nextInt();
            System.out.println("请再次输入新密码：");
            int b =input.nextInt();
            if (a==b){
                System.out.println("密码修改成功");
                System.out.println("当前密码为："+ a);
                return a;
            }else {
                System.out.println("两次输入密码不一致，请重新输入");
                System.out.println("当前密码为:"+mima);
                return mima;
            }

        }else {
            System.out.println("旧密码输入错误");
            System.out.println("当前密码为:"+mima);
            return mima;
        }
    }
//菜单7
    public static void q7(){
        System.out.println("1.查询余额 2.存款 3.取款 4.修改密码 5.退出");
    }
//是否操作  8
    public static boolean q8(String a){
        if (a.equals("y")){
            return true;
        }else if (a.equals("n")){
            System.exit(0);
            return false;
        }else {
            System.out.println("请输入正确的指令");
            return false;
        }
    }


/**
 * main主方法
  */

    public static void main(String[] args) {
    String name = "dingning";
    int key = 123456;
    double yue = 10000;
        double q = 0.0;
        q1();
        for (int i = 3;i>0;i--){
            boolean isRight = q2(name,key);
            if (isRight){
                System.out.println("登陆成功");
                break;
            }else {
                System.out.println("账户名或密码错误，请重新输入，今日还剩"+(i - 1)+"次机会");
            }
        }
        boolean b = true;
       while (b){
           System.out.println("是否继续（y/n）");
           Scanner input = new Scanner(System.in);
           String a =input.next();
           b=q8(a);
           q7();
           int c = input.nextInt();
           switch (c){
               case 1:
                   q3(yue);
                   break;
               case 2:
                   System.out.println("请输入存款金额");
                   double saving = input.nextDouble();
                   double t =q4(saving,yue);
                   yue = t;
                   break;
               case 3:
                   System.out.println("请输入取款金额");
                   double geting =input.nextDouble();
                   double y = q5(geting,yue);
                   yue = y;
                   break;
               case 4:
                   System.out.println("请输入旧密码");
                   int mima =input.nextInt();
                   int o = q6(key,mima);
                   key = o;
                   break;
               case 5:
                   System.exit(0);
                   break;
           }

       }




}

}
